package org.tangsu.service;

import com.google.errorprone.annotations.Var;
import lombok.Data;
import org.tangsu.dao.BaseDao;
import org.tangsu.entity.MstscEntity;

import java.sql.SQLException;
import java.util.List;

@Data
public class MstscEntitServiceImpl {
    BaseDao dao;

    public MstscEntitServiceImpl() throws Exception {
        dao = new BaseDao();
    }

    public List<MstscEntity> findAll() throws SQLException, InstantiationException, IllegalAccessException {
        return dao.findAll(BaseDao.buildSelectSql(new MstscEntity()) + " order by order1 "
                , MstscEntity.class);
    }

    public MstscEntity insert(MstscEntity e) throws SQLException, InstantiationException, IllegalAccessException {
        dao.insert(e);
        dao.submitNoClose();
        return e;
    }

    public MstscEntity update(MstscEntity e) throws SQLException, InstantiationException, IllegalAccessException {
        dao.updateById(e);
        dao.submitNoClose();
        return e;
    }

    public int delete(String id) throws SQLException, InstantiationException, IllegalAccessException {
        int i = dao.deleteById(id, MstscEntity.class);

        dao.submitNoClose();

        return i;
    }
}
